package com.cds.alert.action;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.cds.alert.ibatis.Criteria;
import com.cds.alert.pojo.AlertAlarmBbs;
import com.cds.alert.pojo.AlertAlarmBlog;
import com.cds.alert.pojo.AlertAlarmChat;
import com.cds.alert.pojo.AlertAlarmFileTransfer;
import com.cds.alert.pojo.AlertAlarmMail;
import com.cds.alert.pojo.AlertAlarmUrl;
import com.cds.alert.service.AlertAlarmBbsService;
import com.cds.alert.service.AlertAlarmBlogService;
import com.cds.alert.service.AlertAlarmChatService;
import com.cds.alert.service.AlertAlarmFileTransferService;
import com.cds.alert.service.AlertAlarmMailService;
import com.cds.alert.service.AlertAlarmUrlService;
import com.cds.alert.service.AlertSysOwnerService;
import com.google.common.collect.Maps;
import com.opensymphony.xwork2.Preparable;

public class AlertAlarmMailAction extends BaseAction implements Preparable {
	private static final long serialVersionUID = 6776558938712115191L;
	private AlertAlarmMail alertAlarmMail;
	private Long id;
	// 是否已读
	private String read;
	@Autowired
	private AlertAlarmMailService alertAlarmMailService;
	@Autowired
	private AlertSysOwnerService alertSysOwnerService;
	@Autowired
	private AlertAlarmUrlService alertAlarmUrlService;
	@Autowired
	private AlertAlarmBbsService alertAlarmBbsService;
	@Autowired
	private AlertAlarmBlogService alertAlarmBlogService;
	@Autowired
	private AlertAlarmFileTransferService alertAlarmFileTransferService;
	@Autowired
	private AlertAlarmChatService alertAlarmChatService;

	private Integer maxLength = 3;

	public void prepare() {
		if (getRequest().getMethod().equalsIgnoreCase("post")
				&& (!"".equals(getRequest().getParameter("alertAlarmMail.id")))) {
			alertAlarmMail = alertAlarmMailService.selectByPrimaryKey(id);
		}
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getRead() {
		return read;
	}

	public void setRead(String read) {
		this.read = read;
	}

	public AlertAlarmMail getAlertAlarmMail() {
		return alertAlarmMail;
	}

	public void setAlertAlarmMail(AlertAlarmMail alertAlarmMail) {
		this.alertAlarmMail = alertAlarmMail;
	}

	public String delete() {

		return SUCCESS;
	}

	public String edit() throws IOException {

		return SUCCESS;
	}

	public String execute() {
		return SUCCESS;
	}

	public String cancel() {
		if (!"list".equals(from)) {
			return "home";
		}
		return "cancel";
	}

	public String save() throws Exception {
		return SUCCESS;
	}

	public String list() {

		return SUCCESS;
	}

	/**
	 * 邮件接收
	 */
	public List<AlertAlarmMail> getReceiveAlertAlarmMailList() {
		Criteria example = new Criteria();
		example.setMysqlOffset(0);
		example.setMysqlLength(maxLength);
		Map<String, Object> condition = Maps.newHashMap();
		condition.put("mode", AlertAlarmMail.RECEIV_MAIL);
		example.setCondition(condition);
		return alertAlarmMailService.query(example);
	}

	/**
	 * 邮件发送
	 */
	public List<AlertAlarmMail> getSendAlertAlarmMailList() {
		Criteria example = new Criteria();
		example.setMysqlOffset(0);
		example.setMysqlLength(maxLength);
		Map<String, Object> condition = Maps.newHashMap();
		condition.put("mode", AlertAlarmMail.SEND_MAIL);
		example.setCondition(condition);
		return alertAlarmMailService.query(example);
	}

	/**
	 * 网站访问
	 */
	public List<AlertAlarmUrl> getAlertAlarmUrlList() {
		Criteria example = new Criteria();
		example.setMysqlOffset(0);
		example.setMysqlLength(maxLength);
		return alertAlarmUrlService.queryByExample(example);
	}

	/**
	 * 论坛发帖
	 */
	public List<AlertAlarmBbs> getAlertAlarmBbsList() {
		Criteria example = new Criteria();
		example.setMysqlOffset(0);
		example.setMysqlLength(maxLength);
		return alertAlarmBbsService.queryByExample(example);
	}

	/**
	 * 微博发帖
	 */
	public List<AlertAlarmBlog> getAlertAlarmBlogList() {
		Criteria example = new Criteria();
		example.setMysqlOffset(0);
		example.setMysqlLength(maxLength);
		return alertAlarmBlogService.queryByExample(example);
	}

	/**
	 * 文件传输
	 */
	public List<AlertAlarmFileTransfer> getAlertAlarmFileTransferList() {
		Criteria example = new Criteria();
		example.setMysqlOffset(0);
		example.setMysqlLength(maxLength);
		return alertAlarmFileTransferService.queryByExample(example);
	}

	/**
	 * 聊天记录
	 */
	public List<AlertAlarmChat> getAlertAlarmChatList() {
		Criteria example = new Criteria();
		example.setMysqlOffset(0);
		example.setMysqlLength(maxLength);
		return alertAlarmChatService.queryByExample(example);
	}
}
